package com.enjoyor.health.HGPT.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.enjoyor.health.HGPT.core.dto.DialogDto;
import com.enjoyor.health.HGPT.core.entity.DialogRecord;
import com.enjoyor.health.HGPT.core.mapper.DialogRecordMapper;
import com.enjoyor.health.HGPT.core.service.IDialogRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 对话-用户对话记录 服务实现类
 * </p>
 *
 * @author enjoyor
 * @since 2023-10-18
 */
@Service
public class DialogRecordServiceImpl extends ServiceImpl<DialogRecordMapper, DialogRecord> implements IDialogRecordService {

    @Override
    public List<DialogDto> getDialogRecordByOpenId(String openId) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("open_id", openId);
        return baseMapper.getDialogRecordByOpenId(map);
    }

    @Override
    public int updateDialogRecordName(String nameNew, String dialogId) {
        LambdaUpdateWrapper<DialogRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(DialogRecord::getId, dialogId)
                .set(DialogRecord::getName, nameNew)
                .set(DialogRecord::getUpdateTime, LocalDateTime.now());
        return baseMapper.update(null, lambdaUpdateWrapper);
    }

    @Override
    public int updateDialogRecordState(int state, String dialogId) {
        LambdaUpdateWrapper<DialogRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(DialogRecord::getId, dialogId)
                .set(DialogRecord::getState, state)
                .set(DialogRecord::getUpdateTime, LocalDateTime.now());
        return baseMapper.update(null, lambdaUpdateWrapper);
    }
}
